{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>发布消息</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" name="add_article" id="add_article" enctype="multipart/form-data">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">标题：</label>
                            <div class="input-group col-sm-4">
                                <input id="title" type="text" class="form-control" name="title" placeholder="输入标题">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label cyanse" for="myEditor">介绍：</label>
                            <div class="input-group col-sm-9">
                                <textarea name="content" style="width:70%;height:200px" id="content"></textarea>
                            </div>
                        </div>
                        <div class="form-group"id="MyContent">
                            <label class="col-sm-3 control-label cyanse" for="myEditor">详情：</label>
                            <div class="input-group col-sm-9">
                                <textarea name="detail" style="width:90%" id="myEditor"></textarea>
                                <a id="myEditors" style="color:#A94543"></a>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label cyanse">消息发送对象：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b" name="cate_id" id="detail_type">
                                    <option value="1">机构</option>
                                    <option value="2">用户</option>
                                </select>

                            </div>
                        </div>
                        <div class="form-group" id="MyType">
                            <label class="col-sm-3 control-label cyanse">机构：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="type_name" id="type_name">
                                    {volist name="mechanism" id="vv"}
                                    <option value="{$vv.mechanism_id}">{$vv.mechanism_name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="user_list" style="display:none">
                            <label class="col-sm-3 control-label">选择用户(机构)：</label>
                            <div class="input-group col-sm-4">
                                <select name="user_id[]"  id="n_user_id" xm-select="select1" lay-verify="required" xm-select-search="">
                                    {volist name="list" id="vo"}
                                      <option value="{$vo.user_id}">{$vo.user_username}({$vo.mechanism_name})</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>





                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary btsave"  type="button"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}

<script>
    wk.upload("{:url('Upload/upload')}",2);

    //    var formSelects = layui.formSelects;
//    formSelects.data('select1', 'local', {
//        arr: [
//            {"name": "分组-1", "type": "optgroup"},
//            {"name": "北京", "value": 1},
//            {"name": "上海", "value": 2},
//            {"name": "分组-2", "type": "optgroup"},
//            {"name": "广州", "value": 3},
//            {"name": "深圳", "value": 4},
//            {"name": "天津", "value": 5}
//        ]
//    });
    $("#detail_type").change(function () {
        var detail_type = $(this).val();
        if(detail_type==2){
            $('#user_list').show();
            $("#MyType").hide();
//            $.ajax({
//                url: "{:url('selectUser')}",
//                type: "post",
//                success:function (data) {
//                    var  html = '';
//
//                    for (var i=0;i<data.data.length;i++)
//                    {
//                        html +="<option value='"+data.data[i].user_id+"'>"+data.data[i].user_username+'('+data.data[i].mechanism_name+')'+"</option>";
//                    }
//
//
//                    $(".n_user_id").append(html);
//                    formSelects.render();
//                }
//            })

        }else if(detail_type==1){
            $('#user_list').hide();
            $("#MyType").show();

        }
    })
</script>
<script type="text/javascript">
    //百度富文本编辑器
    var editor = UE.getEditor('myEditor', {
        initialFrameHeight:450,
        autoHeight: false,
        autoHeightEnabled:false,
        autoFloatEnabled:false
    });
</script>
<script>

    $(".btsave").on('click',function () {
//        var content = $.trim($("#myEditor").val());
        var title = $.trim($("#title").val());
         if(title<1){
            layer.msg("信息标题不能为空", {icon: 1, time: 1500, shade: 0.1}, function (index) {
            });
            return false;
        }
//        if(content>200){
//            layer.msg("信息介绍不能超过200个字节", {icon: 1, time: 1500, shade: 0.1}, function (index) {
//            });
//            return false;
//        }
        $.ajax({
            url: "{:url('add')}",
            type: "post",
            dataType: "json",

            data: $("#add_article").serialize(),
            success: function (data) {
                if (data.code == 200) {
                    wk.success(data.msg,1,"{:url('notice/index')}");
                } else if(data.code == 100){
                    $('.btn').removeAttr('disabled');
                    wk.error(data.msg,2,'');
                    return false;
                }
            }
        });
    })
</script>
</body>

</html>